package plus.stmt;

import plus.VScope;
import plus.exp.Exp;
import plus.run.Emit;
import plus.run.Label;

public class P_While extends Loop {
	final Exp condition;
	final Statement stmt;
	VScope inner;

	public P_While(String label, Exp condition, Statement stmt) {
		super(label);
		this.condition = condition;
		this.stmt = stmt;
	}
	@Override
	public void threadScope() {
		condition.threadScope();
		VScope.enterBlock();
		enter();
		inner = VScope.current;
		stmt.threadScope();
		exit();
		VScope.exit();
	}
	@Override
	public void compile() {
		again.JMP();
		Label body = new Label();
		body.post();
		Emit.pop();
		stmt.compile();
		again.post();
		condition.compileJcc(body, true);
		Emit.pop();
		after.post();
	}
}
